/*-------------------<-- Start of Description-->---------------------\ | Retrieve the column number of a variable from a dataset; | | Can be used to check to see if a dataset has a variable; | |---------------------<-- End of Description-->----------------------| |--------------------------------------------------------------------| |------------<-- Start of Files or Arguments Needed-->---------------| | arguments: | | indata = the name of a data set you want to explore; | | varname = variable name; | |-------------<-- End of Files or Arguments Needed-->----------------| |--------------------------------------------------------------------| |------------------<-- Start of Files Created-->---------------------| | Example: %varnum(one, pt); / %varnum(one, pt); | | Usage: %varnum(indata,varname); | \-------------------<-- End of Files Created-->---------------------*/ %macro varnum(indata,varname); /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 3-3-2001 11:27pm; | | Modified: 8-30-2001 9:24pm; | | Purpose: Return the column of a variable in| | the dataset; | \--------------------------------------------*/ %local _varnumdsid_ _varnumrc_; %let _varnumdsid_=%sysfunc(open(&indata)); %if &_varnumdsid_ %then %do; %if (%length(&varname)>0) %then %do; %if %sysfunc(varnum(&_varnumdsid_,&varname)) %then %sysfunc(varnum(&_varnumdsid_,&varname)); %else 0; %end; %let _varnumrc_=%sysfunc(close(&_varnumdsid_)); %end; %else %do; %put ==> Alert! Open data set "&indata" failed.; 0 %end; %mend varnum;